import { defineStore } from 'pinia'
import {useHideMenuListApi, useMenuNavApi, useMenuTypeListApi} from '@/api/sys/menu'
import { generateRoutes } from '@/router'
import { RouteRecordRaw } from 'vue-router'

export const routerStore = defineStore('routerStore', {
	state: () => ({
		menuRoutes: [] as RouteRecordRaw[],
		menuHideRoutes: [] as RouteRecordRaw[],
		routes: [] as RouteRecordRaw[],
		params: {} as {[key: string]: any}
	}),
	actions: {
		async getMenuRoutes() {
			const { data } = await useMenuNavApi()
			const routes = generateRoutes(data)
			this.menuRoutes.push(...routes)

			// 常量菜单
			// const constantRoutes = generateRoutes(constantMenu)
			// this.menuRoutes.push(...constantRoutes)

			return this.menuRoutes
		},
		async getHideMenuRoutes(){
			const { data } = await useHideMenuListApi(3)
			const routes = generateRoutes(data)
			this.menuHideRoutes.push(...routes)
			return this.menuHideRoutes
		},
		setRoutes(routers: RouteRecordRaw[]) {
			this.routes = routers
		},
		setParams(key: string, data: any){
			this.params[key] = data
		}
	},
	getters: {
		getParams: (state) =>{
			return (key: string) => state.params[key]
		},
	}
})
